package com.dubbo.provider.util;

import com.alibaba.fastjson.JSONObject;
import com.dubbo.provider.entity.Invocation;

import java.io.IOException;


/**
 * @description: 发送请求
 * @author: 石亚宁
 * @create: 2020-05-28 16:42
 **/

public class HttpClient {
	public String send(String hostName,int port, Invocation invocation) throws IOException {
		/*URL url=new URL("http",hostName,port,"/");
		HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
		urlConnection.setRequestMethod("POST");
		urlConnection.setDoOutput(true);

		OutputStream outputStream = urlConnection.getOutputStream();
		ObjectOutputStream objectOutputStream=new ObjectOutputStream(outputStream);
		objectOutputStream.writeObject(invocation);

		objectOutputStream.flush();
		objectOutputStream.close();
		InputStream inputStream = urlConnection.getInputStream();
		return IOUtils.toString(inputStream);*/

		return   HTTPUtil.postJSON(hostName + ":" + port, JSONObject.toJSONString(invocation));

	}
}
